package com.atguigu.cloud.result;

import com.atguigu.cloud.myEnum.ReturnCodeEnum;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.List;

@Data
@Accessors(chain = true)
public class Result<T> {

    /**
     * 返回编码
     */
    private String code;

    /**
     * 返回信息
     */
    private String message;

    /**
     * 返回数据
     */
    private T data;

    /**
     * 调用接口时间
     */
    private long timestamp;

    /**
     * 初始化返回数据的时间
     */
    public Result() {
        this.timestamp = System.currentTimeMillis();
    }

    public static <T> Result<T> success(T data) {
        Result<T> resultData = new Result<T>();
        resultData.setCode(ReturnCodeEnum.SUCCESS.getValue());
        resultData.setMessage(ReturnCodeEnum.SUCCESS.getDesc());
        resultData.setData(data);
        return resultData;
    }

    public static <T> Result<T> fail(String code,String message) {
        Result<T> resultData = new Result<T>();
        resultData.setCode(code);
        resultData.setMessage(message);
        return resultData;
    }

}
